﻿using RTracker.Models.Common;
using RTracker.Models.ErrorLog;
using RTracker.Models.User;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;


namespace RTracker.Areas.Recruitment.Models.Department
{
    public class MDepartment
    {

        /// static variable RowSize from config settings to get list of this row size.
        public static int nRowSize = Convert.ToInt32(ConfigurationManager.AppSettings["TotalRecordsInListUser"]);

        /// <summary>
        /// This method is used to create a Department in the database.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the department.</param>
        /// <returns>CStatus which is an object that contain transaction details</returns>
        public CStatus CreateDepartment(CAuthenticationContext objCAuthenticationContext, ref CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_create_department_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@client_id", SqlDbType.Int).Value = objCDepartment.ClientId;
                    cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = objCDepartment.OrganizationId;
                    cmd.Parameters.Add("@department_name", SqlDbType.NVarChar).Value = objCDepartment.DepartmentName    ;
                    cmd.Parameters.Add("@department_desc", SqlDbType.NVarChar).Value = objCDepartment.DepartmentDesc;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// This method is used to delete a department in the database.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus DeleteDepartment(CAuthenticationContext objCAuthenticationContext, ref CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_delete_department_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;
                    cmd.Parameters.Add("@department_ids", SqlDbType.NVarChar).Value = objCDepartment.DepartmentIds;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// This method is used to update the Department's detail in the database.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus UpdateDepartment(CAuthenticationContext objCAuthenticationContext, ref CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_update_department_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = objCDepartment.OrganizationId;
                    cmd.Parameters.Add("@client_id", SqlDbType.Int).Value = objCDepartment.ClientId;
                    cmd.Parameters.Add("@department_name", SqlDbType.NVarChar).Value = objCDepartment.DepartmentName;
                    cmd.Parameters.Add("@department_desc", SqlDbType.NVarChar).Value = objCDepartment.DepartmentDesc;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// This method is used to get the Department's detail in the database.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus GetDepartmentDetail(CAuthenticationContext objCAuthenticationContext, ref CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();
            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("r_get_department_detail_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;

                    SqlDataAdapter adp = new SqlDataAdapter(cmd);

                    DataTable dt = new DataTable();

                    int rowsAffected = adp.Fill(dt);

                    if (rowsAffected > 0)
                    {
                        objCDepartment = dt.ConvertToListFromDataTableDepartment()[0];
                    }

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.DetailSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// Sets the softlock on the record whose Id is passed.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus SetDepartmentSoftLock(CAuthenticationContext objCAuthenticationContext, CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_set_department_soft_lock_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// Sets the hardlock on the record whose Id is passed.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus SetDepartmentHardLock(CAuthenticationContext objCAuthenticationContext, CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_set_department_hard_lock_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// Releases the softlock on the record whose Id is passed.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus ReleaseDepartmentSoftLock(CAuthenticationContext objCAuthenticationContext, CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_release_department_soft_lock_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        /// Releases the hardlock on the record whose Id is passed.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about user's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus ReleaseDepartmentHardLock(CAuthenticationContext objCAuthenticationContext, CDepartment objCDepartment)
        {
            CStatus oCStatus = new CStatus();

            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_release_department_hard_lock_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@created_by", SqlDbType.Int).Value = objCAuthenticationContext.UserId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }
            return oCStatus;
        }

        /// <summary>
        ///  This function is used to get complete User list
        /// </summary>
        /// <returns>List of type CUser</returns>
        public GDepartment GetDepartmentGridList(CDepartment objCDepartment, CAuthenticationContext objCAuthenticationContext)
        {
            GDepartment objGDepartment = new GDepartment();
            int nTotalRecords = 0;
            int nCurrentRowSize = nRowSize;

            if (objCDepartment.RowSize != 0)
            {
                nCurrentRowSize = objCDepartment.RowSize;
            }
            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("r_get_department_paging_list_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@department_id", SqlDbType.Int).Value = objCDepartment.DepartmentId;
                    cmd.Parameters.Add("@organization", SqlDbType.Int).Value = objCDepartment.OrganizationId;
                    cmd.Parameters.Add("@page_number", SqlDbType.Int).Value = objCDepartment.PageNumber;
                    cmd.Parameters.Add("@row_size", SqlDbType.Int).Value = nCurrentRowSize;
                    cmd.Parameters.Add("@sort_on", SqlDbType.VarChar).Value = objCDepartment.SortOn;
                    cmd.Parameters.Add("@sort_type", SqlDbType.VarChar).Value = objCDepartment.SortType;
                    cmd.Parameters.Add("@search", SqlDbType.VarChar).Value = objCDepartment.Search;

                    cmd.Parameters.Add("@searchon", SqlDbType.VarChar).Value = objCDepartment.SearchOn;
                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    cmd.Parameters["@error"].Direction = ParameterDirection.Output;
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);

                    DataTable dt = new DataTable();

                    int rowsAffected = adp.Fill(dt);

                    objGDepartment.Paging = new CPaging();
                    if (rowsAffected > 0)
                    {
                        objGDepartment.LstDepartment = dt.ConvertToListFromDataTableDepartment();
                        objGDepartment.LstDepartment[0].PageNumber = int.Parse(cmd.Parameters["@idOut"].Value.ToString());
                        objGDepartment.Paging.PageNumber = objGDepartment.LstDepartment[0].PageNumber;
                    }
                    else
                    {
                        objGDepartment.LstDepartment = null;
                    }


                    nTotalRecords = int.Parse(cmd.Parameters["@error"].Value.ToString());

                    objGDepartment.Status = new CStatus();

                    if (nTotalRecords < 0)
                    {
                        objGDepartment.Status.Success = false;
                        objGDepartment.Status.StatusDetails = nTotalRecords.DbError();
                    }
                    else
                    {
                        objGDepartment.Paging.TotalRecordsCount = nTotalRecords;
                        objGDepartment.Paging.PageSize = nCurrentRowSize;

                        objGDepartment.Status.Success = true;
                        objGDepartment.Status.StatusDetails = "success";
                    }
                }
                catch (Exception ex)
                {
                    objGDepartment.Status = new CStatus();
                    objGDepartment.Status.Success = false;
                    objGDepartment.Status.StatusDetails = ex.Message;
                }
            }
            return objGDepartment;
        }

        /// /// <summary>
        ///  This function is used to get complete Department list working under a same organization.
        /// </summary>
        /// <param name="objCAuthenticationContext">This object contains information about Department's authentication context.</param>
        /// <param name="objCDepartment">This object contains details of the Department.</param>
        /// <param name="lstCDepartment">"out" the list of Departments</param>
        /// <returns>CStatus which is an object that contain transaction details.</returns>
        public CStatus GetDepartmentList(CAuthenticationContext objCAuthenticationContext, int organizationId, out List<CDepartment> lstCDepartment)
        {
            CStatus oCStatus = new CStatus();
            lstCDepartment = new List<CDepartment>();
            using (SqlConnection con = new SqlConnection(CCommonCollection.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("r_get_department_list_procedure", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@organization_id", SqlDbType.Int).Value = organizationId;

                    cmd.Parameters.Add("@idOut", SqlDbType.Int).Value = null;
                    cmd.Parameters["@idOut"].Direction = ParameterDirection.Output;
                    //cmd.Parameters.Add("@error", SqlDbType.Int).Value = null;
                    //cmd.Parameters["@error"].Direction = ParameterDirection.Output;
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);

                    DataTable dt = new DataTable();

                    int rowsAffected = adp.Fill(dt);

                    if (rowsAffected > 0)
                    {
                        lstCDepartment.AddRange(dt.ConvertToListFromDataTableDepartment());
                    }

                    if (Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()) > 0)
                    {
                        oCStatus.Success = true;
                        oCStatus.StatusDetails = CAppConstants.SessionSuccess;
                    }
                    else
                    {
                        oCStatus.Success = false;
                        oCStatus.StatusDetails = Convert.ToInt32(cmd.Parameters["@idOut"].Value.ToString()).DbError();
                        //oCStatus.StatusDetails = CAppErrorsConstants.SomethingWentWrong;
                    }
                }
                catch (Exception ex)
                {
                    oCStatus.Success = false;
                    oCStatus.StatusDetails = ex.Message;
                }
            }


            return oCStatus;
        }


    }

    public static class MDepartmentConverter
    {
        private static Boolean ColContain(DataTable dt, DataRow dtRow, string colname)
        {
            Boolean res = false;
            if (dt.Columns.Contains(colname) && dtRow[colname] != DBNull.Value)
            {
                res = true;
            }
            return res;
        }
        public static List<CDepartment> ConvertToListFromDataTableDepartment(this DataTable dt)
        {

            List<CDepartment> lstTemp = new List<CDepartment>();

            foreach (DataRow dtRow in dt.Rows)
            {
                CDepartment objTemp = new CDepartment();

                if (ColContain(dt, dtRow, "department_id"))
                    objTemp.DepartmentId = Convert.ToInt32(dtRow["department_id"]);
                if (ColContain(dt, dtRow, "organization_id"))
                    objTemp.OrganizationId = Convert.ToInt32(dtRow["organization_id"]);
                if (ColContain(dt, dtRow, "client_id"))
                    objTemp.ClientId = Convert.ToInt32(dtRow["client_id"]);
                if (ColContain(dt, dtRow, "department_name"))
                    objTemp.DepartmentName = Convert.ToString(dtRow["department_name"]);
                if (ColContain(dt, dtRow, "department_desc"))
                    objTemp.DepartmentDesc = Convert.ToString(dtRow["department_desc"]);

                if (ColContain(dt, dtRow, "is_soft_locked"))
                    objTemp.IsSoftLocked = Convert.ToBoolean(dtRow["is_soft_locked"]);
                if (ColContain(dt, dtRow, "soft_locked_by"))
                    objTemp.SoftLockedBy = Convert.ToInt32(dtRow["soft_locked_by"]);
                if (ColContain(dt, dtRow, "soft_lock_timestamp"))
                    objTemp.SoftLockTimestamp = Convert.ToDateTime(dtRow["soft_lock_timestamp"]);
                if (ColContain(dt, dtRow, "is_hard_locked"))
                    objTemp.IsHardLocked = Convert.ToBoolean(dtRow["is_hard_locked"]);
                if (ColContain(dt, dtRow, "hard_locked_by"))
                    objTemp.HardLockedBy = Convert.ToInt32(dtRow["hard_locked_by"]);
                if (ColContain(dt, dtRow, "hard_lock_timestamp"))
                    objTemp.HardLockTimestamp = Convert.ToDateTime(dtRow["hard_lock_timestamp"]);
                if (ColContain(dt, dtRow, "create_timestamp"))
                    objTemp.CreateTimestamp = Convert.ToDateTime(dtRow["create_timestamp"]);
                if (ColContain(dt, dtRow, "created_by"))
                    objTemp.CreatedBy = Convert.ToInt32(dtRow["created_by"]);
                if (ColContain(dt, dtRow, "modified_timestamp"))
                    objTemp.ModifiedTimestamp = Convert.ToDateTime(dtRow["modified_timestamp"]);
                if (ColContain(dt, dtRow, "modified_by"))
                    objTemp.ModifiedBy = Convert.ToInt32(dtRow["modified_by"]);
                if (ColContain(dt, dtRow, "delete_flag"))
                    objTemp.DeleteFlag = Convert.ToBoolean(dtRow["delete_flag"]);

                lstTemp.Add(objTemp);

            }
            return lstTemp;
        }
    }
}